#!/usr/bin/python3
# -*- coding: utf-8 -*-

import logging
import argparse
import os.path

try:
    import efl.evas as evas
    import efl.ecore as ecore
    import efl.edje as edje
    import efl.elementary as elm
    from efl.elementary import ELM_POLICY_QUIT, \
        ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
    from efl.elementary.window import Window, StandardWindow, ELM_WIN_BASIC, \
        ELM_WIN_DIALOG_BASIC
    from efl.elementary.background import Background
    from efl.elementary.box import Box
    from efl.elementary.label import Label
    from efl.elementary.naviframe import Naviframe
    from efl.elementary.popup import Popup
    from efl.elementary.button import Button
    from efl.elementary.scroller import Scroller, ELM_SCROLLER_POLICY_OFF, \
        ELM_SCROLLER_POLICY_AUTO
    from efl.elementary.check import Check
    from efl.elementary.progressbar import Progressbar
    from efl.elementary.genlist import Genlist, GenlistItemClass
    from efl.elementary.segment_control import SegmentControl
    from efl.elementary.frame import Frame
    from efl.elementary.entry import Entry
    from efl.elementary.icon import Icon
    from efl.elementary.layout import Layout
    from efl.elementary.theme import Theme
except:
    import elementary as elm
    import evas, e_dbus, ecore, edje
    from e_dbus import DBusEcoreMainLoop
    from elementary import Window, Background, Box, Label, Naviframe, Popup, \
        Button, Scroller, Check, Progressbar, Genlist, GenlistItemClass, \
        SegmentControl, Frame, Entry, Icon, Layout, Theme, ELM_WIN_BASIC, \
        ELM_WIN_DIALOG_BASIC, ELM_POLICY_QUIT, ELM_SCROLLER_POLICY_OFF, \
        ELM_SCROLLER_POLICY_AUTO, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
        
import ere.primitives as Prim
import ere.editor as Editor
import ere.browser as Browser
import ere.batcher as Batcher
import ere.overview as Overview

log = logging.getLogger()

EXPAND_BOTH = (evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
EXPAND_HORIZ = (evas.EVAS_HINT_EXPAND, 0.0)
FILL_BOTH = (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL)

###############################################################################

class main_window:
    def __init__(self):
        self.create_window()
        self.mainWin.show()
        
    def create_window(self):
        self.mainWin= StandardWindow('eRe', 'enlightened RAW editor')
        self.mainWin.icon_name= "eRe"
        self.mainWin.autodel= True
        self.mainWin.size = (900, 700)
        
        self.set_main_box()
        self.create_view_buttons()
        
    def set_main_box(self):
        self.mainBox= Prim.add_box (self.mainWin)
        
    def create_views_types(self):
        self.views= []

        self.views.append (Overview.Overview (self.frame,
                                              "Overview tab"))
        self.views.append (Browser.Browser (self.frame,
                                            "Browser tab"))
        self.views.append (Batcher.Batcher (self.frame,
                                            "Batcher tab"))
        self.views.append (Editor.Editor (self.frame,
                                          "Editor tab"))
        
    def create_view_buttons(self):
        self.buttonsFrame, self.buttonBox= Prim.add_frame_and_box(self.mainBox, "Views buttons")
        self.buttonBox.horizontal= True
        self.buttonsFrame.autocollapse= True
        self.create_views()
        self.create_views_types()
        
        for view in self.views:
            button= Button(self.buttonBox, text= '%s' % view.__class__.__name__)
            button.callback_clicked_add(view.show_view, self.viewsBox)
            button.show()
            self.buttonBox.pack_end(button)

        
    def create_views(self):
        self.frame, self.viewsBox= Prim.add_frame_and_box(self.mainBox, "Views")
        self.viewsBox.horizontal= True
        Prim.add_label(self.viewsBox, "Box de vistas<br>")

###############################################################################

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="RAW image editor for Enlightenment")
    parser.add_argument("-v", "--verbose", action="count")
    args = parser.parse_args()

    level = logging.WARNING
    if args.verbose:
        level -= 10 * args.verbose
    log.setLevel(level)

    elm.init()
    elm.policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED)

    for td in ("./data/theme/default.edj", "@PKGDATADIR@/theme/default.edj"):
        if os.path.exists(td):
            Theme(default=True).extension_add(td)

    mainWin= main_window()

    elm.run()
    elm.shutdown()